package com.monkeyboy.utils;

import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertiesUtils {

	private PropertiesUtils() {
	}

	/**
	 * @Description 读取classPath下面的Properties文件，返回一个Map
	 * @param fileName
	 */
	public static Map<String, String> readClassPathProperties(String fileName) throws Exception {
		if (fileName == null || fileName.trim().length() == 0)
			return null;
		InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
		Map<String, String> reMap = new HashMap<>();
		Properties properties = new Properties();
		properties.load(in);
		Enumeration<Object> keys = properties.keys();
		while (keys.hasMoreElements()) {
			String key = keys.nextElement().toString();
			reMap.put(key, properties.getProperty(key));
		}
		return reMap;
	}
	public static void main(String[] args) throws Exception {
		System.out.println(readClassPathProperties("application.properties"));
	}
}
